package com.data.common.entity;

import cn.hutool.core.util.ArrayUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.*;

/**
 * excel 单元格 对象
 */
@ApiModel(value="excel单元格对象", description="excel")
public class CellRowAndColDTO {
    @ApiModelProperty("开始行")
    private int row;
    @ApiModelProperty("开始列")
    private int col;
    @ApiModelProperty("单元格 合并列 个数")
    private int cellCol;
    @ApiModelProperty("单元格 合并行 个数")
    private int cellRow;
    @ApiModelProperty("值信息")
    private String cellValue;
    @ApiModelProperty("单元格坐标位置")
    private String[] position;

    private List<String> keys = new ArrayList<>();

    public List<String> getKeys() {
        return keys;
    }


    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public int getCellCol() {
        return cellCol;
    }

    public void setCellCol(int cellCol) {
        this.cellCol = cellCol;
    }

    public int getCellRow() {
        return cellRow;
    }

    public void setCellRow(int cellRow) {
        this.cellRow = cellRow;
    }

    public String getCellValue() {
        return cellValue;
    }

    public void setCellValue(String cellValue) {
        this.cellValue = cellValue;
        // 计算 坐标位置 A,1
        StringBuffer sb = new StringBuffer("");
        sb.append((char)(this.getCol() +65))
                .append("-")
                .append(this.getRow() +1);
        if(this.getCellCol() > 1 ){
            for(int c = 2;c <= this.getCellCol();c ++){
                sb.append(":")
                        .append((char)(this.getCol() +65 + c -1))
                        .append("-")
                        .append(this.getRow() +1);
            }
        }

        if(this.getCellRow() > 1) {
            for (int r =  2; r <= this.getCellRow() ; r ++) {
                sb.append(":")
                        .append((char) (this.getCol() + 65))
                        .append("-")
                        .append(this.getRow() + r );
            }
        }

        this.setPosition(sb.toString().split(":"));
        //设置 keys
        String[] ps = this.getPosition();
        Set<String> ks = new HashSet<>();
        Arrays.asList(ps).stream().forEach(key->{
            ks.addAll(Arrays.asList(key.split("-")));
        });
        this.keys.addAll(ks);
    }

    public String[] getPosition() {
        return position;
    }

    public void setPosition(String[] position) {
        this.position = position;
    }




}
